package com.wanho.java156.controller;

import com.github.pagehelper.PageInfo;
import com.wanho.java156.po.Order;
import com.wanho.java156.service.OrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/order")
@RequiresRoles("订单管理员")
public class OrderController {
    @Autowired
    private OrderService orderService ;
    @GetMapping("/view")
    public ModelAndView view(String id){
        Order orders = orderService.view(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("pages/orders-show");
        modelAndView.addObject("orders",orders) ;
        return modelAndView ;
    }

    @RequiresPermissions("订单管理")
    @GetMapping("/list")
    public ModelAndView list(
            @RequestParam(name = "page",required = false,defaultValue = "1") int pageNum,
            @RequestParam(name = "size",required = false,defaultValue = "5") int pageSize,
            @RequestParam(required = false,defaultValue = "") String ordernum){
        PageInfo<Order> pageInfo = orderService.list(pageNum,pageSize,ordernum);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("pages/orders-page-list");
        modelAndView.addObject("pageInfo",pageInfo) ;
        return modelAndView ;
    }

    /*@GetMapping("/list")
    public ModelAndView list(){
        List<Order> ordersList = orderService.list();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("pages/orders-list");
        modelAndView.addObject("ordersList",ordersList) ;
        return modelAndView ;
    }*/
}
